package fr.esiag.isidis.xmlParse;

import java.io.File;

import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;
import javax.xml.bind.Marshaller;
import javax.xml.bind.Unmarshaller;

import fr.esiag.isidis.epp.generatedClasses.QueryExportCdc;

public class JaxbObjectsConverter {
	
	private Marshaller marshaller;
	private Unmarshaller unmarshaller;
	
	
	/*
	 * getters and setters 
	 */
	public void setMarshaller(Marshaller marshaller) {
		this.marshaller = marshaller;
	}

	public Unmarshaller getUnmarshaller() {
		return unmarshaller;
	}

	public void setUnmarshaller(Unmarshaller unmarshaller) {
		this.unmarshaller = unmarshaller;
	}
	
	/*
	 * mapping XML files to Objects (unmarshalling)
	 */
	
	public QueryExportCdc mapXmlToObject(String fileName){
		
		try{
			JAXBContext jc = JAXBContext.newInstance("jaxBgeneratedClasses/fr.esiag.isidis.epp.generatedClasses");
			unmarshaller = jc.createUnmarshaller();
			QueryExportCdc QEC = (QueryExportCdc) unmarshaller.unmarshal(new File(fileName));
			return QEC;
		
		}catch(Exception e){
			e.printStackTrace();
			return null;
		}
	}
	
	/*
	 * mapping Objects to XML files (marshalling)
	 */
	
//	public boolean mapObjectToXml(String fileName, QueryExportCdc QEC){
//		try{
//			JAXBContext jc = JAXBContext.newInstance("jaxBgeneratedClasses/fr.esiag.isidis.epp.generatedClasses");
//			marshaller = jc.createMarshaller();
//			marshaller.marshal(QEC, new File(fileName));
//			return true;
//		
//		}catch(Exception e){
//			e.printStackTrace();
//			return false;
//		}
//		
//	}
}
